package com.jn.exam.exam.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jn.exam.R;
import com.jn.exam.exam.entity.Student;
import com.jn.exam.exam.entity.StudentConnection;
import com.jn.exam.exam.entity.vo.ExamStudentVo;
import com.jn.exam.exam.service.ExamService;
import com.jn.exam.exam.service.PaperConsumerService;
import com.jn.exam.exam.service.StudentConnectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 江南大学1033190417
 * @date 2022/3/16 20:59
 */
@RestController
@RequestMapping("/exam/statistical")
@Api(description = "考试统计相关")
public class ExamStatisticalController {

    @Autowired
    private StudentConnectionService studentConnectionService;

    @Autowired
    private ExamService examService;

    @Autowired
    private PaperConsumerService paperConsumerService;

    @ApiOperation("查询某场考试的最高分，最低分，平均分")
    @GetMapping("getMaxMinAvgScoreOfExam")
    public R getMaxMinAvgScoreOfExam(String examId) {
        Map<String, Object> result = studentConnectionService.getMaxMinAvgScoreOfExam(examId);
        return R.ok().data("result", result);
    }


    /**
     * 是否作弊  0/1          这里应该设置为0
     * 阅卷情况：3种  -1/0/1  这里应该设置为1
     * 参加情况：3中  -1/0/1  这里应该设置为1
     * lowScore 低分
     * highScore 高分
     *如果current和limit传入的是空，会返回所有 应该可以用于画图统计之类的
     * @param examStudentVo 条件  具体不止上面所说，去类里面看
     *
     * @return 学生列表
     */
    @ApiOperation("查询参加某场考试的所有学生（含分数）")
    @PostMapping("getAllStudentForExam")
    public R getAllStudentForExam(@RequestBody ExamStudentVo examStudentVo) {
        Integer total = examService.getPageStudentForExamTotal(examStudentVo);
        if (total == 0) {
            return R.ok().data("total", total).data("rows", null);
        }
        Long current = examStudentVo.getCurrent();
        Long limit = examStudentVo.getLimit();
        if (current != null && limit != null) {
            examStudentVo.setCurrent(current * limit);
        }
        List<Student> students = examService.getPageStudentForExam(examStudentVo);
        return R.ok().data("total", total).data("rows", students);
    }

    @ApiOperation("查询考试每个分数的人数")
    @GetMapping("queryNumberOfPerScore")
    public R queryNumberOfPerScore(String examId){
        List<Map<String,Object>> result=examService.queryNumberOfPerScore(examId);//肯定是没有作弊的
        return R.ok().data("result",result);
    }


    @ApiOperation(value = "查询一道题目的得分情况")
    @GetMapping("getStatisticalOfOnePaperQuestion")
    public R getStatisticalOfOnePaperQuestion(String paperQuestionId){
        return paperConsumerService.getStatisticalOfOnePaperQuestion(paperQuestionId);
    }




}
